package com.iot08.admin.controller;

import com.iot08.admin.controller.base.BaseController;
import com.iot08.admin.service.OperationService;
import com.iot08.admin.service.page.PageVO;
import com.iot08.admin.service.page.PageableImpl;
import com.iot08.common.entity.admin.Operation;
import com.iot08.common.entity.admin.SysUser;
import com.iot08.common.response.Response;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Description: 操作日志
 * @author: Rock
 * @time: 2020/9/11 17:34
 */
@Controller
@RequestMapping("operation")
public class OperationController extends BaseController {

    @Resource
    private OperationService operationService;

    /**
     * @param [page, type, role, ip, startTime, endTime]
     * @time: 2020/9/11 18:07
     * @author: Rock
     * @version 1.0
     */
    @RequestMapping("list/{type}")
    public ModelAndView list(@PathVariable Integer type, PageVO page, String role, String ip,
                             String startTime, String endTime) {
        ModelAndView mv = new ModelAndView();
        SysUser user = this.getSessionUser();
        Page<Operation> pages = operationService.list(page, type, role, ip, startTime, endTime, user);
        mv.addObject("operations", pages.getContent());
        if (pages.getPageable() instanceof PageableImpl) {
            PageableImpl pi = (PageableImpl) pages.getPageable();
            mv.addObject("page", pi.getPage());
        }
        mv.addObject("roleName", role);
        mv.addObject("startTime", startTime);
        mv.addObject("endTime", endTime);
        mv.addObject("userType", user.getType());
        mv.addObject("butSet", getMyBut(page.getMenuId()));
        mv.addObject("type", type);
        mv.setViewName("operation/operation_list");
        return mv;
    }

    /**
     * 删除
     *
     * @param [ids]
     * @time: 2020/9/14 9:41
     * @author: Rock
     * @version 1.0
     */
    @ResponseBody
    @RequestMapping(value = "del", method = RequestMethod.POST)
    public Response<Object> del(String ids, Integer type) {
        return operationService.del(type, this.getSessionUser(), ids, this.getRemortIP());
    }


}
